// pages/mine/fensi/fensi.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    active: 0,
    list:[],
    pageNum: 1,
    pageSize: 7,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    let that = this
    if(this.data.active == 0){
      var postObj = {
        url: '/mobileUser/follow/getMyFollow?pageNum=' + this.data.pageNum + '&pageSize=' + this.data.pageSize,
        method: 'get'
      }
      app.request.wxRequest(postObj).then(res => {
        if (res.data.code === 200) {
          let data = res.data.rows
          for(var i = 0;i< res.data.rows.length;i++)
          res.data.rows[i].bieRen.image = app.util.config().api+ res.data.rows[i].bieRen.image
          // that.setData({
          //  list: data
          // })
            // console.log(data)
            // res.data.rows = data
            var navList = this.data.list
            var rows = res.data.rows
            var allArr = [...navList, ...rows]
            this.setData({
              list  : allArr
            })
  
        }
      })
    } else {
      var postObj = {
        url: '/mobileUser/follow/getMyFans?pageNum=' + this.data.pageNum + '&pageSize=' + this.data.pageSize,
        method: 'get'
      }
      app.request.wxRequest(postObj).then(res => {
        if (res.data.code === 200) {
          // let data = res.data.rows
          // that.setData({
          //  list: data
          // })
          for(var i = 0;i< res.data.rows.length;i++)
          if(res.data.rows[i].bieRen)
          res.data.rows[i].bieRen.image = app.util.config().api+ res.data.rows[i].bieRen.image          
            // console.log(data)
            var navList = this.data.list
            var rows = res.data.rows
            var allArr = [...navList, ...rows]
            this.setData({
              list  : allArr
            })
  
        }
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this
    that.setData({
      pageNum: that.data.pageNum + 1
    })
    that.onShow()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onChange(event) {
    // console.log(event)
    this.setData({
      active:event.detail.name,
      list:[],
      pageNum:1,
    })
    this.onShow()
  },
  todingdan() {
    wx.navigateTo({
      url: 'chat/chat'
    })
  }
})